package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;

import com.sanjiahantang.ythshopping.model.BaseModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.CheckView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zy on 2017/8/28.
 */

public class CheckPresenter extends BasePresenter{

    private CheckView checkView;
    public CheckPresenter(CheckView checkView){
        this.checkView = checkView;
    }

    public void checkKey(final Context context,final String url){
        initLoadDialog(context);
        mLoadingDialog.show();

        Map<String,String> para = new HashMap();
        para.put("key",ConfigValue.DATA_KEY);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "user/isappkey",para ,new BaseDelegate.ResultCallback<BaseModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(BaseModel response, Object tag) {
                dismiss();
                checkView.getData(response,url);
            }
        });
    }
}
